# -*- coding: utf-8 -*-

# Scrapy settings for scrapy_demo project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://docs.scrapy.org/en/latest/topics/settings.html
#     https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://docs.scrapy.org/en/latest/topics/spider-middleware.html

BOT_NAME = 'crawler'

SPIDER_MODULES = ['crawler.spiders']
NEWSPIDER_MODULE = 'crawler.spiders'

# mysql数据库
MYSQL_HOST = '192.168.0.122'
MYSQL_USER = 'root'
MYSQL_PWD  = 'qxtwFknlx9(f'
MYSQL_NAME = 'fsh_crawler'
MYSQL_PORT = 3306
REDIS_PARAMS={'password': 'qxtwFknlx9(f'}

# redis数据库
REDIS_HOST = "192.168.0.127"
REDIS_PORT = 6379
REDIS_DB = 0
REDIS_PWD = 'qxtwFknlx9(f'

REDIS_START_URLS_AS_SET = True

# ip代理池 个人房源*列表页
REDIS_PROXIES_FIRST = 'crawler:proxies_A'
REDIS_PROXIES_SECOND = 'crawler:proxies_B'
# 任务执行表
REDIS_TASK_RUNNING = 'crawler:running:{task_id}'
# code表
REDIS_CODES = {
    'city': 'xzs:city',
    'orientation': 'xzs:dict:orientation',
    'web': 'xzs:dict:web_belong',
    'district': 'xzs:district:{sub_str}',
    'spare': 'xzs:spare:{sub_str}',
    'property_year': 'xzs:dict:property_year',
    'property_type': 'xzs:dict:property_type',
    'decoration': 'xzs:dict:decoration',
    'architecturaltype': 'xzs:dict:architecturaltype',
    'lease_type': 'xzs:dict:rent_type',
    'pay_type': 'xzs:dict:pay_type'
}
# 房源数据判重，房源id及基本信息表
# 'crawler:houses:<mysql_table_name>:<webcode>'
REDIS_HOUSES = 'crawler:houses:{mysql_table_name}:{webcode}'
REDIS_HOUSES_CSOWNER = 'crawler:houses:crawler_ershoufang_owner:{webcode}'
REDIS_HOUSES_CZOWNER = 'crawler:houses:crawler_chuzu_owner:{webcode}'
REDIS_HOUSES_CSAGENT = 'crawler:houses:crawler_ershoufang_agent:{webcode}'
REDIS_HOUSES_SPOWNER = 'crawler:houses:crawler_shangpu_owner:{webcode}'

# 自定义配置 个人房源*列表页
MIDDLEWARES_OWNER_FIRST = {
        'ITEM_PIPELINES': {
            'crawler.pipelines.EsfOwnerListPipeline': 300,
            'crawler.pipelines.EsfOwnerRedisPipeline': 400
        },
        'DOWNLOADER_MIDDLEWARES': {
            'crawler.middlewares.ProxyPoolsFirst': 125,
            'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 123,
            'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': 2,
            'crawler.middlewares.UserAgentProxy': 4
        },
        'CONCURRENT_REQUESTS': 2,
        'DOWNLOAD_TIME': 5
    }

# 自定义配置 个人房源*详情页
MIDDLEWARES_OWNER_SECOND = {
        'ITEM_PIPELINES': {
            'crawler.pipelines.EsfOwnerDetailPipeline': 300
        },
        'DOWNLOADER_MIDDLEWARES' : {
            'crawler.middlewares.ProxyPoolsSecond': 125,
            'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 123,
            'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': 2,
            'crawler.middlewares.UserAgentProxy': 4
        },
        'CONCURRENT_REQUESTS': 2,
        'DOWNLOAD_TIME': 3
    }

# 自定义配置 个人房源*详情页
MIDDLEWARES_OWNER_THIRD = {
        'ITEM_PIPELINES': {
            'crawler.pipelines.EsfOwnerDetailPipeline': 300
        },
        'DOWNLOADER_MIDDLEWARES' : {
            'crawler.middlewares.ProxyPoolsThird': 125,
            'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 123,
            'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': 2,
            'crawler.middlewares.UserAgentProxy': 4
        },
        'CONCURRENT_REQUESTS': 3,
        'DOWNLOAD_TIME': 3
    }

# 自定义配置 出租房源*列表页
MIDDLEWARES_RENT_FIRST = {
        'ITEM_PIPELINES': {
            'crawler.pipelines.RentOwnerListPipeline': 300,
            'crawler.pipelines.RentOwnerRedisPipeline': 400
        },
        'DOWNLOADER_MIDDLEWARES': {
            'crawler.middlewares.ProxyPoolsFirst': 125,
            'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 123,
            'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': 2,
            'crawler.middlewares.UserAgentProxy': 1
        },
        'CONCURRENT_REQUESTS': 2,
        'DOWNLOAD_TIME': 5
    }

# 自定义配置 出租房源*详情页
MIDDLEWARES_RENT_SECOND = {
        'ITEM_PIPELINES': {
            'crawler.pipelines.RentOwnerDetailPipeline': 300
        },
        'DOWNLOADER_MIDDLEWARES' : {
            'crawler.middlewares.ProxyPoolsSecond': 125,
            'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 123,
            'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': 2,
            'crawler.middlewares.UserAgentProxy': 4
        },
        'CONCURRENT_REQUESTS': 2,
        'DOWNLOAD_TIME': 3
    }

# 自定义配置 个人房源*详情页
MIDDLEWARES_RENT_THIRD = {
        'ITEM_PIPELINES': {
            'crawler.pipelines.RentOwnerDetailPipeline': 300
        },
        'DOWNLOADER_MIDDLEWARES' : {
            'crawler.middlewares.ProxyPoolsThird': 125,
            'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 123,
            'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': 2,
            'crawler.middlewares.UserAgentProxy': 4
        },
        'CONCURRENT_REQUESTS': 3,
        'DOWNLOAD_TIME': 3
    }

# 需爬取详情的房源详情页链接
REDIS_DETAILLINK_CSOWNER = 'crawler:detaillink_csowner'
REDIS_DETAILLINK_CZOWNER = 'crawler:detaillink_czowner'

REDIS_DETAILLINK_CSOWNER_OUT = 'crawler:detaillink_csowner_out'
REDIS_DETAILLINK_CZOWNER_OUT = 'crawler:detaillink_czowner_out'

# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'scrapy_demo (+http://www.yourdomain.com)'

# Obey robots.txt rules
# ROBOTSTXT_OBEY = True

# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
#DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
#COOKIES_ENABLED = False

# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False

# Override the default request headers:
#DEFAULT_REQUEST_HEADERS = {
#   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#   'Accept-Language': 'en',
#}

# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
#    'scrapy_demo.middlewares.ScrapyDemoSpiderMiddleware': 543,
#}

# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
#    'scrapy_demo.middlewares.ScrapyDemoDownloaderMiddleware': 543,
#}

# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
#}

# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
#ITEM_PIPELINES = {
#    'scrapy_demo.pipelines.ScrapyDemoPipeline': 300,
#}

# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
#AUTOTHROTTLE_ENABLED = True
# The initial download delay
#AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
#AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
#HTTPCACHE_IGNORE_HTTP_CODES = []
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
